from ..original.orders_api import OrdersAPI


class Orders(object):

    @classmethod
    def delete_an_order(cls, transaction_id: str, order_id=False):
        """
        删除一个订单
        :param transaction_id:运输追踪号
        :param order_id: 订单号
        """
        return OrdersAPI().delete_pending_order(transaction_id, order_id)
        
        # try:
        #     if order_id:
        #         response = OrdersAPI.delete_pending_order(transaction_id, order_id)
        #     else:
        #         response = OrdersAPI.delete_pending_order(transaction_id)
        #     flag = response.get('Result')
        #     if flag == 'OK':
        #         return True, response
        #     else:
        #         return False, "连接失败，失败原因：{}".format(response['Error'])
        # except Exception as e:
        #     return False, '调用接口失败，失败原因：{}'.format(e)

    @classmethod
    def get_order_tracking(cls, tracking_number: str):
        """
        获取订单运输信息
        :param tracking_number:订单的追踪号
        """
        try:
            response = OrdersAPI.get_order_tracking(tracking_number)
            if len(response['Details'])>0:
                result = {'status_code': response['StatusCode'],
                          'estimated_delivery_date': response['EstimatedDeliveryDate'],
                          'details': response['Details']}
                return True, result
            else:
                return False, "连接失败，失败原因：{}".format(response['Error'])
        except Exception as e:
            return False, '调用接口失败，失败原因：{}'.format(e)
